package com.example.fitnessservice.module.dao.courseMapper;

import com.example.fitnessservice.module.pojo.CourseDetailsCamp;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.Date;
import java.util.List;

/**
 * @author feng
 * @version 1.0
 * @&#064;description: TODO
 * @&#064;date 2022/11/25 10:31
 */
@Mapper
public interface CampCourseMapper {
    /**
     * 课程状态更新
     *
     * @return 更新的行数
     */
    @Update("update course_details_camp set course_status=1 where #{date} > course_end_time")
    Integer updateCourseStatus3(Date date);

    @Update("update course_details_camp set course_status=4 where #{date} < course_end_time and NOW() > course_start_time")
    Integer updateCourseStatus2(Date date);

    @Update("update course_details_camp set course_status=2 where #{date} < course_start_time")
    Integer updateCourseStatus1(Date date);

    @Select("select * from course_details_camp where course_id=#{campCourseId}")
    List<CourseDetailsCamp> findCourseDetailsById(Integer campCourseId);

    @Update("update course_details_camp set course_num=course_num+1 where course_id=#{courseId}")
    Integer campNumAdd(Integer campCourseId);

    @Update("update course_details_camp set course_num=course_num-1 where course_id=#{courseId}")
    Integer campNumReduce(Integer campCourseId);

    @Select("select course_coach_id from course_details_camp where course_id=#{campCourseId}")
    List<Integer> findCoachId(Integer campCourseId);

    @Select("select * from course_details_camp where course_id=#{courseId} and course_start_time>#{time}")
    List<CourseDetailsCamp> findCourseDetailsByIdAndTime(@Param("courseId") Integer campCourseId, @Param("time") Date applyTime);

    @Update("update course_details_camp set course_status=4 where course_status=2 course_id=#{couserId} and corse_start_time<NOW() and course_end_time>NOW()")
    Integer takeCourse(Integer courseId);

    @Select("select * from course_details_camp where course_id=#{courseId} and course_start_time<NOW() and course_end_time>NOW()")
    CourseDetailsCamp findNowCourse(Integer courseId);
}

